import VueRouter from "vue-router"
import Home from "../view/Home"
import Login from "../view/Login"
import Vue from "vue"
import ElementUI from "element-ui"

Vue.use(ElementUI)

const router = new VueRouter({
    routes : [
        {
            name : 'Home',
            path : '/home',
            component: Home
        },
        {
            name : 'Login',
            path : '/',
            component : Login
        },
        {

        }
    ],
})

router.beforeEach((to, from,next)=>{
    if(to.path === '/Home' || to.path === '/home'){
        const token = sessionStorage.getItem('token')
        if(token){
            next()
        }
        else{
            next('/')

            // 这里最好自定义弹窗
            alert('账号密码不能为空')


        }
    }else{
        next()
    }
})

export default router